package com.cloudbroker.bcs.common.mycat.route.function;

import com.cloudbroker.bcs.common.mycat.config.model.rule.RuleAlgorithm;

/**
 * Created by xuyn15828 on 2016/6/7.
 */
public abstract class AbstractPartitionAlgorithm implements RuleAlgorithm {

    public void init() {
    }

    public Integer[] calculateRange(String beginValue, String endValue) {
        return new Integer[0];
    }

    public static Integer[] calculateSequenceRange(AbstractPartitionAlgorithm algorithm, String beginValue, String endValue) {
        Integer begin = Integer.valueOf(0);
        Integer end = Integer.valueOf(0);
        begin = algorithm.calculate(beginValue);
        end = algorithm.calculate(endValue);

        if ((begin == null) || (end == null)) {
            return new Integer[0];
        }

        if (end.intValue() >= begin.intValue()) {
            int len = end.intValue() - begin.intValue() + 1;
            Integer[] re = new Integer[len];

            for (int i = 0; i < len; i++) {
                re[i] = Integer.valueOf(begin.intValue() + i);
            }

            return re;
        }
        return null;
    }
}
